package com.example.courseapp.activity;

import static com.example.courseapp.activity.RecordActivity2.filterLastSevenDays;
import static com.example.courseapp.activity.RecordActivity2.getBMI;
import static com.example.courseapp.activity.RecordActivity2.recommendExercise;
import static com.example.courseapp.activity.RecordActivity2.validateExerciseDuration;

import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.blankj.utilcode.util.LogUtils;
import com.example.courseapp.R;
import com.example.courseapp.RetrofitHelper;
import com.example.courseapp.bean.ChildInformation;
import com.example.courseapp.bean.ChildSportRecords;
import com.example.courseapp.bean.NewFoodInfo;
import com.example.courseapp.bean.SportRem;
import com.example.courseapp.net.CourseService;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SportRecordActivity extends AppCompatActivity {
    /*推荐食谱*/

    List<String> foodL = new ArrayList<>();
    CourseService service;
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_record);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });


        findViewById(R.id.back).setOnClickListener(v -> {
            finish();
        });
        TextView textView4 = findViewById(R.id.textView4);

        textView4.setText("建议运动方案");
        service = RetrofitHelper.getInstance().createService(CourseService.class);

        textView = findViewById(R.id.myContent);

        getData();
    }

    private void getData() {
        Integer childID = getIntent().getIntExtra("childID", 0);
        service.getSportRemByCid(childID).enqueue(new Callback<SportRem>() {
            @Override
            public void onResponse(Call<SportRem> call, Response<SportRem> response) {
                SportRem sportRem = response.body();
                runOnUiThread(() -> {
                    if (sportRem != null && sportRem.getSportContent() != null && !sportRem.getSportContent().isEmpty()) {
                        textView.setText(sportRem.getSportContent());
                    } else {
                        textView.setText("今日运动已达标，请继续保持~");
                    }
                });
            }

            @Override
            public void onFailure(Call<SportRem> call, Throwable t) {
                LogUtils.e("error === "+t);
                textView.setText("暂无推荐!!");
            }
        });
    }


}